package world2d;
import box2D.collision.shapes.B2PolygonShape;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2BodyDef;
import box2D.dynamics.B2DebugDraw;
import box2D.dynamics.B2FixtureDef;
import box2D.dynamics.B2World;
import data.Object2DData;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.GraphicsPath;

import openfl.display.Sprite;

/**
 * ...
 * @author Marcos Martinez
 */
class Brick2D  extends Sprite
{

	private var m_cWorld:B2World;
	private var m_physScale:Float = 1;
	private var m_cShape:B2PolygonShape;
	private var m_cBodyDef:B2BodyDef;
	private	var m_cBody:B2Body;
	private var m_cFixtureDef:B2FixtureDef ;
	
	public function new(cWorld:B2World) 
	{
		super();
		m_cWorld = cWorld;
		// Add bodies
		m_cFixtureDef = new B2FixtureDef();
		m_cShape = new B2PolygonShape();
		m_cBodyDef = new B2BodyDef();
		m_cBodyDef.type = B2Body.b2_dynamicBody;
		m_cFixtureDef.density = 1.0;
		m_cFixtureDef.friction = 0.5;
		m_cFixtureDef.restitution = 0.1;
		m_cFixtureDef.shape = m_cShape;
		
	}
	
	public function createBox(nWidth:Int, nHeight:Int, nPosX:Int, nPosY:Int):Void
	{	
		m_cShape.setAsBox((nWidth) / m_physScale, (nHeight) / m_physScale);
		m_cBodyDef.position.set((nPosX) / m_physScale, (nPosY) / m_physScale);
		m_cBody = m_cWorld.createBody(m_cBodyDef);
		var cData :Object2DData = new Object2DData();
		cData.m_nName = "brick";
		m_cBody.setUserData(cData);
		m_cBody.createFixture(m_cFixtureDef);	
	}
	
}